#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1 << 24;

ll f[N], g[N], n, m, K, h[N];

int get() {
	static char s[50];
	scanf("%s", s + 1); int res = 0;
	rep(i, 1, K) { res = res * 4 + (s[i] == 'R' ? 1 : s[i] == 'S' ? 2 : 3); }
	return res;
}

void trans(ll *f, ll tp) {
	for(int i = 0; i < K + K; i += 2) {
		rep(j, 0, (1 << K + K) - 1) {
			int b = j >> i & 3, t = j - b * (1 << i);
			if(b != 0) f[t] += tp * f[j];
		}
	}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	K = in, n = in, m = in;
	rep(i, 1, n) f[get()]++; rep(i, 1, m) g[get()]++;
	trans(f, 1); trans(g, 1); rep(i, 0, (1 << K + K) - 1) f[i] = f[i] * g[i];
	trans(f, -1); rep(i, 0, (1 << K + K) - 1) h[i] = f[i];
	for(int i = 0; i < K + K; i += 2) {
		rep(j, 0, (1 << K + K) - 1) {
			int b = j >> i & 3, t = j - b, bb = 1 << i;
			if(b == 0) {
				ll tot = h[t] + h[t + bb] + h[t + bb * 2] + h[t + bb * 3];
				h[t] = tot;
				h[t + bb] = tot - h[t + bb];
				h[t + bb * 2] = tot - h[t + bb * 2];
				h[t + bb * 3] = tot - h[t + bb * 3];
			}
		}
	}
	rep(j, 0, (1 << K + K) - 1) {
		int v = 0;
		for(int i = 0; i < K + K; i += 2) v += (j >> i & 3) == 0;
		if(!v) printf("%lld\n", n * m - h[j]);
	}
	return 0;
}
